package edu.univercidade.tcc.sap.shared;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class CryptUtil {

	private CryptUtil(){}

	public static final String hexaSHA1(String password) {
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			md.update(password.getBytes());
			byte[] bytes = md.digest();
			StringBuilder s = new StringBuilder();
			for (int i = 0; i < bytes.length; i++) {
				int parteAlta = ((bytes[i] >> 4) & 0xf) << 4;
				int parteBaixa = bytes[i] & 0xf;
				if (parteAlta == 0)
					s.append('0');
				s.append(Integer.toHexString(parteAlta | parteBaixa));
			}
			return s.toString();
		} catch (NoSuchAlgorithmException e) {
			return "";
		}
	}
	
}
